import { ILoadMapTypeAll } from '@/common';
import { getTenantID } from '@/utils';

/**
 * 处理 oldState, state 的参数数据
 * @param orderState  业务详情
 * @param orderType 工单类别
 * @returns
 */
const HandleFlowStateCommon = (orderState: string, orderType: string) => {
  let oldState: string = '';
  let nowState: string = '';
  let inventoryState: string = '';
  // if (orderState ? orderState?.endsWith('1000') : '') {

  /**采购需求状态判断*/
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1009`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll.NEED_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll.NEED_STATE}1008`;
      oldState = `${getTenantID()}${ILoadMapTypeAll.NEED_STATE}1000`;
    }
  }

  /**意向公开状态*/
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1019`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.DISCLOSURE_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.DISCLOSURE_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.DISCLOSURE_STATE}1000`;
    }
  }

  /**变更采购申请 [暂时用需求的orderType] [变更：`${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1013`]*/
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1013`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.PURCHASE_CHANGEWAY}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.PURCHASE_CHANGEWAY}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.PURCHASE_CHANGEWAY}1000`;
    }
  }

  /** 采购申请状态判断 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1011`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.PURAPPLY_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.PURAPPLY_STATE}1002`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.PURAPPLY_STATE}1000`;
    }
  }

  /** 文件编制审批状态 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1014`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1000`;
    }
  }

  /** 招标公告 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1015`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1003`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1013`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.CURRYOUT_STATE}1003`;
    }
    // else if (orderState?.endsWith(`${ILoadMapTypeAll.CONTRACT_STATE}1012`)) {
    //   nowState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1012`;
    //   oldState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1003`;
    // }
  }

  /**组建评标委员会*/
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1016`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.EXPERT_BUSINESSTYPE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.EXPERT_BUSINESSTYPE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.EXPERT_BUSINESSTYPE}1000`;
    }
  }

  /** 采购澄清 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1012`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.PROCURECLARFY_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.PROCURECLARFY_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.PROCURECLARFY_STATE}1000`;
    } else if (orderState?.endsWith(`${ILoadMapTypeAll.PROCURECLARFY_STATE}1003`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.PROCURECLARFY_STATE}1003`;
      oldState = getTenantID() + `${ILoadMapTypeAll.PROCURECLARFY_STATE}1001`;
    }
  }

  /** 定标 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1017`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1000`;
    } else if (orderState?.endsWith(`${ILoadMapTypeAll.CALIBRATE_STATE}1003`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.CALIBRATE_STATE}1003`;
      oldState = getTenantID() + `${ILoadMapTypeAll.CALIBRATE_STATE}1001`;
    }
  }

  /** 定标 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1017`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1000`;
    } else if (orderState?.endsWith(`${ILoadMapTypeAll.CALIBRATE_STATE}1003`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.CALIBRATE_STATE}1003`;
      oldState = getTenantID() + `${ILoadMapTypeAll.CALIBRATE_STATE}1001`;
    }
  }

  // ======================  资产管理系统判断state使用  =====================
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1028`) {
    // 材料转资产
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ASSET_TOASSET}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ASSET_TOASSET}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ASSET_TOASSET}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1023`) {
    // 资产调剂
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_TRANS_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1022`) {
    // 资产领用
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_USE_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_USE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_USE_STATUS}1000`;
    } else if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_USE_STATUS}1002`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_USE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_USE_STATUS}1002`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1024`) {
    // 资产退库
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_RETURN_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_RETURN_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_RETURN_STATUS}1000`;
    } else if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_RETURN_STATUS}1002`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_RETURN_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_RETURN_STATUS}1002`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1025`) {
    // 资产报废
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_HANDLE_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1026`) {
    // 资产调拨
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_TRANSFER_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_TRANSFER_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_TRANSFER_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1021`) {
    // 到货验收
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.STORAGE_INSPECTION_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.STORAGE_INSPECTION_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.STORAGE_INSPECTION_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1027`) {
    // 盘点计划
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ASSET_INPLAY_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ASSET_INPLAY_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ASSET_INPLAY_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1030`) {
    // 盘点差异
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ASSET_SUMMARY_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ASSET_SUMMARY_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ASSET_SUMMARY_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1029`) {
    // 资产维保
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ASSET_MAINTENANCE_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ASSET_MAINTENANCE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ASSET_MAINTENANCE_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1031`) {
    // 入库登记
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ENTER_STORE_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ENTER_STORE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ENTER_STORE_STATUS}1000`;
    }
  } else if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1032`) {
    // 资产信息变更
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.ASSET_CHANGE_STATUS}1000`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.ASSET_CHANGE_STATUS}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.ASSET_CHANGE_STATUS}1000`;
    }
  }

  /** 合同管理 */
  if (orderType == `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}1020`) {
    if (orderState?.endsWith(`${getTenantID()}${ILoadMapTypeAll?.CONTRACT_STATE}1000`)) {
      nowState = `${getTenantID()}${ILoadMapTypeAll?.CONTRACT_STATE}1001`;
      oldState = `${getTenantID()}${ILoadMapTypeAll?.CONTRACT_STATE}1000`;
    } else if (orderState == `${getTenantID()}${ILoadMapTypeAll.CONTRACT_STATE}1003`) {
      nowState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1003`;
      oldState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1003`;
    } else if (orderState?.endsWith(`${ILoadMapTypeAll.CONTRACT_STATE}1007`)) {
      nowState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1001`;
      oldState = getTenantID() + `${ILoadMapTypeAll.CONTRACT_STATE}1007`;
    }
  }
  // } else {
  //   nowState = orderState;
  //   oldState = orderState;
  // }

  return {
    oldState,
    state: nowState,
    inventoryState,
  };
};

export { HandleFlowStateCommon };
